Operating on the semantic graph

All model configurations in Simantics are stored into a semantic graph database. Therefore it is the most primitive interface for accessing Simantics and in principle everything is doable with it, although sometimes with a great effort.

Understanding semantic graphs

The best tool for discovering how the model configuration is represented in the Simantics, is Graph debugger. It can be opened from Window/Show View/Other. Resources can be dragged to the debugger from the model browser.

The debugger shows the URI of the resource and all statements related to it.

Accessing resources

data Resource (Simantics/DB)

A resource is a node in a semantic graph.

resource :: String -> <ReadGraph> Resource (Simantics/DB)

Converts an absolute URI to a resource

relativeResource :: Resource -> String -> <ReadGraph> Resource (Simantics/DB)

Converts a relative URI to a resource starting from the given resource

possibleResource :: String -> <ReadGraph> Maybe Resource (Simantics/DB)

Converts an absolute URI to a resource or returns Nothing if there is no such resource.

uriOf :: Browsable a => a -> <ReadGraph> String (Simantics/DB)

Returns the URI of the given value.

currentModel :: <ReadGraph> Resource (Simantics/DB)

Gives the current active model.

(#) :: Resource -> Resource -> <ReadGraph> [Resource] (Simantics/DB)

subject # predicate returns all objects with the given subject and predicate.

possibleObject :: Resource -> Resource -> <ReadGraph> Maybe Resource (Simantics/DB)

If there is exactly one object with the given subject and predicate, possibleObject subject predicate returns it. Otherwise, it returns Nothing.

singleObject :: Resource -> Resource -> <ReadGraph> Resource (Simantics/DB)

Assumes that there is exactly one object with the given subject and predicate and returns it.

data Statement (Simantics/DB)

A statement is an edge in a semantic graph.

statements :: Resource -> Resource -> <ReadGraph> [Statement] (Simantics/DB)

statements subject predicate` returns all statements with the given subject and predicate.

singleStatement :: Resource -> Resource -> <ReadGraph> Statement (Simantics/DB)

Assumes that there is exactly one statement with the given subject and predicate and returns it.

Reading literal values

relatedValue :: Serializable a => Resource -> Resource -> <ReadGraph> a (Simantics/DB)

Reads the value of a literal that is an object with the given subject and predicate

nameOf :: Browsable a => a -> <ReadGraph> String (Simantics/DB)

Reads the name of the value.

Type queries

isInstanceOf :: Resource -> Resource -> <ReadGraph> Boolean (Simantics/DB)

isInstanceOf r t returns true, if r is an instance of t

isSubrelationOf :: Resource -> Resource -> <ReadGraph> Boolean (Simantics/DB)

isSubrelationOf r s returns true, if r is s or a subrelation of s, directly or transitively

isInheritedFrom :: Resource -> Resource -> <ReadGraph> Boolean (Simantics/DB)

isInheritedFrom r t returns true, if r is t or inherits from t, directly or transitively

singleTypeOf :: Resource -> Resource -> <ReadGraph> Resource (Simantics/DB)

singleTypeOf resource baseType returns the principal type of resource that is baseType or inherits from it. Fails if there is not exactly one such type.

possibleTypeOf :: Resource -> Resource -> <ReadGraph> Maybe Resource (Simantics/DB)

As singleTypeOf but returns Nothing when the resource has no principal type inheriting from the given base type, or more than one.

Transactions

The graph database can be accessed only in reading or writing transactions. The SCL console creates the transaction automatically if necessary, but sometimes it is necessary to control manually where the transactions are started.

syncRead :: (() -> <Proc,ReadGraph> a) -> <Proc> a (Simantics/DB)

Executes a read transaction and waits that it completes.

syncWrite :: (() -> <Proc,ReadGraph,WriteGraph> a) -> <Proc> a (Simantics/DB)

Executes a write transaction and waits that it completes.

asyncRead :: (() -> <Proc,ReadGraph> a) -> <Proc> () (Simantics/DB)

Begins a read transaction and immediately returns.

asyncWrite :: (() -> <Proc,ReadGraph,WriteGraph> a) -> <Proc> () (Simantics/DB)

Begins a write transaction and immediately returns.

Writing

newResource :: () -> <WriteGraph> Resource (Simantics/DB)

Creates a new resource.

claim :: Resource -> Resource -> Resource -> <WriteGraph> () (Simantics/DB)

Adds a statement to the semantic graph.

claimRelatedValue :: Serializable a => Resource -> Resource -> a -> <WriteGraph> () (Simantics/DB)

Sets the value of the literal that is an object with the given subject and predicate.

deny :: Resource -> Resource -> Resource -> <WriteGraph> () (Simantics/DB)

Removes a statement with the given subject, predicate and object

Entities

Didn't find the type class 'Entity'.

Searching

searchByType :: Resource -> Resource -> <ReadGraph> [Resource] (Simantics/Model)

searchByType indexRoot type returns the resources of the given type that are indexed by indexRoot, by the index roots that indexRoot is linked to (L0.IsLinkedTo), and by the global ontologies.

The links are followed recursively: the index roots linked to a linked index root are consulted as well, to any depth. Each index root is consulted once however many paths reach it, so links that form a cycle neither repeat the search nor make it fail.

searchByTypeShallow :: Resource -> Resource -> <ReadGraph> [Resource] (Simantics/Model)

As searchByType but consults only the index of the given index root, not the indexes of linked index roots or global ontologies.

searchByTypeAndName :: Resource -> Resource -> String -> <ReadGraph> [Resource] (Simantics/Model)

As searchByType but returns only the resources whose name is the given name.

searchByTypeAndNameShallow :: Resource -> Resource -> String -> <ReadGraph> [Resource] (Simantics/Model)

As searchByTypeAndName but consults only the index of the given index root.

searchByQuery :: Resource -> String -> <ReadGraph> [Resource] (Simantics/Model)

searchByQuery indexRoot query returns the resources that match the given index query. The query is a Lucene query over the indexed fields of the entities, such as Name:Pump*. The same indexes are searched as by searchByType.

searchByQueryShallow :: Resource -> String -> <ReadGraph> [Resource] (Simantics/Model)

As searchByQuery but consults only the index of the given index root.

Simantics/Model/searchByTypeAndFilter